﻿<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
    <meta charset="utf-8"/>
    <meta name="viewport" content="width=device-width, initial-scale=1.0"/>
    <title>登录</title>

    <!-- BOOTSTRAP STYLES-->
    <link href="assets/css/bootstrap.min.css" rel="stylesheet"/>
    <!-- FONTAWESOME STYLES-->
    <link href="assets/css/font-awesome.css" rel="stylesheet"/>
    <!-- GOOGLE FONTS-->
    <link href='https://fonts.googleapis.com/css?family=Open+Sans' rel='stylesheet' type='text/css'/>
</head>
<body style="background-color: #E2E2E2;">
<div class="container">
    <div class="row text-center " style="padding-top:100px;">
        <div class="col-md-12">
            <h1>QHIT-Y-电力巡检系统</h1>
        </div>
    </div>
    <div class="row ">

        <div class="col-md-4 col-md-offset-4 col-sm-6 col-sm-offset-3 col-xs-10 col-xs-offset-1">

            <div class="panel-body">
                <div role="form">
                    <hr/>
                    <h5>Enter Details to Login</h5>
                    <br/>
                    <div class="form-group input-group">
                        <span class="input-group-addon"><i class="fa fa-tag"></i></span>
                        <input type="text" id="userName" name="userName" class="form-control" value="admin"
                               placeholder="Your Username "/>
                    </div>
                    <div class="form-group input-group">
                        <span class="input-group-addon"><i class="fa fa-lock"></i></span>
                        <input type="password" id="userpassword" name="userpassword" class="form-control" value="123456"
                               placeholder="Your Password"/>
                    </div>
                    <div class="form-group">
                        <label class="checkbox-inline">
                            <input type="checkbox"/> Remember me
                        </label>
                        <span class="pull-right"> <a href='javascript: fgpas()'>Forget password ? </a> </span>
                    </div>
                    <div class="form-group">
                        <button id="submit" class="btn btn-primary ">Login Now</button>
                    </div>
                    <hr/>
                    <p style="text-align: center">
                        只要你有一件合理的事去做<br/>你的生活就会显得特别美好
                    </p>
                </div>
            </div>
        </div>
    </div>
</div>

<script src="assets/js/jquery.min.js"></script>
<!-- BOOTSTRAP SCRIPTS -->
<script src="assets/js/bootstrap.min.js"></script>
<script type="application/javascript">
    $(function () {
        $("#submit").click(function () {
            subAjax();
        })
    })

    function subAjax() {
        var date = new Date();
        var year = date.getFullYear();
        var month = date.getMonth() + 1;
        var day = date.getDate();
        var time = year + "-" + month + "-" + day;
        //------------------------------------------
        var userName = $("#userName").val().trim();
        var userpassword = $("#userpassword").val().trim();
        $.ajax({
            url: "http://localhost:8080/user/login",
            type: "post",
            data: {"userName": userName, "userpassword": userpassword,"lastLoginTime":time},
            dataType: "json",
            success: function (data) {
                if (data.status == 200) {
                    //名字，登录的时间
                    var userName = data.obj.userName;
                    var lastLoginTime = data.obj.lastLoginTime
                    sessionStorage.setItem("userName", userName);
                    sessionStorage.setItem("lastLoginTime", lastLoginTime);
                    window.location.href = "index.html";
                }
            },
            error: function () {
                console.log("与后台断开连接！！！");
            }
        })
    }

    function fgpas() {
        alert("忘记密码")
    }


</script>

</body>
</html>
